package com.ikingtech.platform.service.system.user.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.platform.service.system.user.entity.UserConfigDO;
import com.ikingtech.platform.service.system.user.mapper.UserConfigMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tie yan
 */
@Service
@RequiredArgsConstructor
public class UserConfigRepository extends ServiceImpl<UserConfigMapper, UserConfigDO> {

    public List<UserConfigDO> listByUserIdAndTenantCode(String userId, String tenantCode) {
        return this.list(Wrappers.<UserConfigDO>lambdaQuery().eq(UserConfigDO::getUserId, userId).eq(UserConfigDO::getTenantCode, tenantCode));
    }

    public void removeByUserId(String userId, String tenantCode) {
        this.remove(Wrappers.<UserConfigDO>lambdaQuery().eq(UserConfigDO::getUserId, userId).eq(UserConfigDO::getTenantCode, tenantCode));
    }

    public String getValueByType(String type) {
        return this.getObj(Wrappers.<UserConfigDO>lambdaQuery().eq(UserConfigDO::getType, type), String.class::cast);
    }

    public void removeByTenantCode(String tenantCode) {
        this.remove(Wrappers.<UserConfigDO>lambdaQuery().eq(UserConfigDO::getTenantCode, tenantCode));
    }

    public boolean existByType(String type) {
        return this.baseMapper.exists(Wrappers.<UserConfigDO>lambdaQuery().eq(UserConfigDO::getType, type));
    }
}
